package com.studentrecipe.mapper;

import com.studentrecipe.pojo.File;
import com.studentrecipe.pojo.Flavor;
import com.studentrecipe.pojo.Ingredient;
import com.studentrecipe.pojo.Recipe;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface MapperSearch {

    @Select("select * from ipd.recipes order by id")
    List<Recipe> searchDefault();

    @Select("select * from ipd.ingredients order by id")
    List<Ingredient> searchIngredientsDefault();

    @Select("select * from ipd.flavors order by id")
    List<Flavor> searchFlavorsDefault();

    @Select("select * from ipd.ingredients where recipe_id = #{id}")
    List<Ingredient> searchIngredients(int id);

    @Select("select * from ipd.flavors where recipe_id = #{id}")
    List<Flavor> searchFlavors(int id);

    List<Integer> searchCondition(
            String title, String[] difficulty, String[] cuisine, String[] calorieLevel, String ingredient,
            String[] flavors, LocalDate startTime, LocalDate endTime, Integer smallTime, Integer bigTime);

    @Select("select * from ipd.recipes where id = #{id}")
    Recipe searchRecipe(int id);

    @Select("select * from ipd.files where recipe_id = #{id}")
    List<File> searchFiles(int id);

    @Select("select id from ipd.recipes where student_id = #{id} order by created_time desc")
    List<Integer> searchId(Integer id);

    @Select("select id from ipd.recipes order by rand() limit 6")
    List<Integer> searchRandom();
}
